home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 September / Australian PC User - September 2003 (CD1).iso / magstuff / web / files / psp801ev.exe / Data1.cab / CenterLayer.PspScript < prev    next >
Encoding:
Text File  |  2003-06-06  |  1.8 KB  |  42 lines

  1. from JascApp import *
  2. import JascUtils
  3.  
  4. def ScriptProperties():
  5.     return {
  6.         'Author': 'Joe Fromm',
  7.         'Copyright': 'Copyright (C) 2002-2003, Jasc Software Inc., All Rights Reserved. Permission to create derivate works of this script is granted provided this copyright notice is included',
  8.         'Description': 'Center the active layer on the canvas',
  9.         'Host': 'Paint Shop Pro 8',
  10.         'Host Version': '8.00'
  11.         }
  12.  
  13. def Do(Environment):
  14.     # we need a document for this to work
  15.     if JascUtils.RequireADoc( Environment ) == App.Constants.Boolean.false:
  16.         return
  17.  
  18.      # need the canvas size, the layer size and the layer position
  19.     CanvasSize = App.TargetDocument.Size
  20.     LayerInfo = App.Do( Environment, 'ReturnLayerProperties' )
  21.     # LayerRect comes back as a tuple of the from ( (x,y), dx, dy )
  22.     # we want to work with a size tuple and a position tuple, so rearrange it.
  23.     if len(LayerInfo['LayerRect']) == 2:
  24.         LayerSize = (LayerInfo[ 'LayerRect' ][1], LayerInfo[ 'LayerRect' ][1] )
  25.     else:
  26.         LayerSize = (LayerInfo[ 'LayerRect' ][1], LayerInfo[ 'LayerRect' ][2] )
  27.     LayerPos =  LayerInfo[ 'LayerRect' ][0]
  28.     
  29.     # now compute how far to move the layer to get it centered
  30.     DesiredPos = ( (CanvasSize[0] - LayerSize[0]) / 2, (CanvasSize[1] - LayerSize[1]) / 2 )
  31.     Offset = ( DesiredPos[0] - LayerPos[0], DesiredPos[1] - LayerPos[1] )
  32.     App.Do( Environment, 'Mover', {
  33.             'Offset': Offset, 
  34.             'Object': App.Constants.LayerOrSelection.Layer, 
  35.             'SelectPoint': None,
  36.             'GeneralSettings': {
  37.                 'ExecutionMode': App.Constants.ExecutionMode.Default, 
  38.                 'AutoActionMode': App.Constants.AutoActionMode.Match
  39.                 }
  40.             })
  41.  
  42.